/**
 * 策略分组选择
 */

 import React,{PropTypes,Component,PureComponent}  from 'react';
 import {Select ,Button ,Modal, Form, TreeSelect,Row,Col,message } from 'antd';
 import { connect } from 'react-redux';

 const TreeNode = TreeSelect.TreeNode;

/**
 * 策略分组选择输入控件
 * @param {[type]} data     [列表数据]
 * @param {[type]} dispatch [方法]
 * @param {[type]} tag      [所属model]
 */

const PolicyGroup=({data,dispatch,tag,groupName,username})=>{
  console.log("PolicyGroup0000",groupName,username);
  const myProps={
		data,
		onChange:(v)=> {
				data.map((item,i)=>{
					if(v===item.groupName){
						// dispatch({
						// 	type: `${tag}/getGroupDate`,
						// 	payload: {
            //     groupNumber:item.groupNumber
						// 	}
						// })
            dispatch({
							type: `${tag}/getfilterProduct`,
							payload: {
                groupName:item.groupName,
                groupNumber:item.groupNumber,
                username:item.username
							}
						})
            dispatch({
							type: `${tag}/setState`,
							payload: {
                groupName:item.groupName,
                groupNumber:item.groupNumber,
                username:item.username,
                isPublic:item.isPublic,
                MAselectedRowKeys:[]
							}
						})
					}
				})
			},
		style:{width:200},
	}

  if(tag == 'fundpool'){
	  return (
      <TreeSelect
        {...myProps}
        showSearch
        placeholder="请选择加入分组"
        dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
        treeCheckable= {true}
        treeDefaultExpandAll={true}
        multiple
      >
        {
  				 data.map((item,i)=>
             <TreeNode
               value={item.groupNumber}
               key={item.groupNumber}
               title={item.groupName}
             />
           )
  			}
  		</TreeSelect>
	  )
  }else if(tag == 'myattention'){

    return (
      <TreeSelect
        {...myProps}
        showSearch
        placeholder="Please select"
        dropdownStyle={{ maxHeight: 200, overflow: 'auto' }}
        treeDefaultExpandAll={true}
        value={username == ''?'Please select':`${username} : ${groupName}`}
      >
        {
  				 data.map((item,i)=>
             <TreeNode
               value={item.groupName}
               key={item.groupNumber}
               title={`${item.username} : ${item.groupName}`}
             />
           )
  			}
  		</TreeSelect>
	  )
  }
}

export {
  PolicyGroup
}
